// =============================================================
// CInfoMap for IST(Index/Search Tool)
// ---------------------------------------
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr or woorung@nhncorp.com
// Date : Jul. 10, 2006
// =============================================================
#ifndef CInfoMapH
#define CInfoMapH
//-----------------------------------------------------------------
#include <iostream>
#include <iterator>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <fstream>
#include <string>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "CScript.h"
//#include "CIndexScript.h"
//#include "CCubeScript.h"

#include "CTask.h"
#include "CWork.h"

using namespace std;
//---------------------------------------------------------------
typedef struct {
	vector< pair<string, string> > attr_val;
} Tcommon_task;

typedef struct {
	string type;
	string name;
	vector<string> commands;
} Twork;

typedef struct {
	string type;
	string name;
	map<string,string> params;
} Tinvoker;

typedef struct {
	string name;
	vector< pair<string, string> > attr_val;
	vector<Twork> works;
	vector<Tinvoker> invokers;

	// in order to sequentially process works and invokers
	vector<string> serial_work_list;
} Ttask;

typedef struct {
	Tcommon_task common_task;
	vector<Ttask> tasks;
} Tinfo_map;
//---------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
	Tinfo_map *get_imap(char *imap_file);
}
#endif
//---------------------------------------------------------------
//class CInfoMap : public CCubeScript {
class CInfoMap : public CScript {
private :
	string imap_file_name;
	Tinfo_map *imap;
	int current_pos;
	vector<CTask> tasks;

protected :
	int addDefaultParameters();
	int replaceCommonAVs();
	int replaceTaskAVs();
	int replaceWorkAVs();
	int makeupTasks();

public :
	CInfoMap(char *imap_file);
	CInfoMap(char *imap_file, vector<string> &args);
	~CInfoMap();

	Tinfo_map *getIMap();
	int hasMoreTasks();
	CTask &getNextTask();
};
//----------------------------------------------------------------
#endif
